﻿
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<base href="<%=basePath%>" />
<title>商品档案</title>
<link rel="stylesheet" href="css/main.css" type="text/css" />
<script language="javascript" src="script/main.js"></script>
<script type='text/javascript' src='dwr/interface/merchandiseAction.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
<script type="text/javascript">
	var textCode;
	var codeChk = false;
	var textAmount;
	function init() {
		textCode = document.getElementById("code");
		textAmount = document.getElementById("amount");
		textCode.focus();

	}
	function out_code() {
		codeChk = false;
		if (trimString(textCode.value).length > 0
				&& trimString(textCode.value).length < 4) {
			merchandiseAction.findMerchandiseByCode(textCode.value, function(
					ret) {
				if (ret > 0) {
					show_message("msg_code", "0", '输入的编号[' + textCode.value
							+ ']重复请重新输入!');
					codeChk = false;
					//textCode.focus();
					//textCode.select();
				} else {
					show_message("msg_code", "1", '输入正确!');
					codeChk = true;
				}
			});
		} else {
			show_message('msg_code', '0', '编号不能为空且不能超过3位长度!');
			codeChk = false;
		}

	}
	function out_amount() {
		var chk = false;

		if ((!isNaN(textAmount.value)) && textAmount.value > 0
				&& textAmount.value < 999) {

			show_message("msg_amount", "1", '输入正确!');
			chk = true;
		} else {
			show_message('msg_amount', '0', '价格必须输入大于零小于999的数字形式');

		}
		return chk;
	}
	function formSubmit() {
		var chk = false;

		var chkRetName = out_chkMaxLength('name', 'msg_name', '名称小于10位且不能为空!',
				'10');
		var chkRetAmount = out_amount();

		if (codeChk && chkRetName && chkRetAmount) {
			chk = true;
		}
		return chk;
	}

	window.onload = init;
</script>
</head>
<body>

<p></p>
<p><font style="font-size: 10pt;">档案管理->商品档案->新增</font></p>

<p></p>
<s:form action="merchandiseAction" method="post" theme="simple"
	onsubmit="return formSubmit();">
	<table border="0" cellpadding="1" cellspacing="1" width="95%">
		<tr>
			<td align="right" width="10%" nowrap="true">商品编号</td>
			<td width="20%"><s:textfield name="merchandise.code"
				cssClass="TextInput" id="code"
				onFocus="show_message('msg_code','2','请输入编号');" onBlur="out_code()"></s:textfield>
			<DIV style="DISPLAY: show" id="msg_code" class="box_div_right">&nbsp;</DIV>
			</td>
			<td align="right" width="10%" nowrap="true">商品名称</td>
			<td><s:textfield name="merchandise.name" cssClass="TextInput"
				id="name" onFocus="show_message('msg_name','2','请输入商品名称');"
				onBlur="out_chkMaxLength('name', 'msg_name', '名称小于10位且不能为空!',
				'10')"></s:textfield>
			<DIV style="DISPLAY: show" id="msg_name" class="box_div_right">&nbsp;</DIV>
			</td>
		</tr>
		<tr>
			<td align="right" width="10%" nowrap="true">商品价格（元）</td>
			<td width="20%"><s:textfield name="merchandise.price"
				cssClass="TextInput" id="amount"
				onFocus="show_message('msg_amount','2','请输入商品价格')"
				onBlur="out_amount()"></s:textfield>
			<DIV style="DISPLAY: show" id="msg_amount" class="box_div_right">&nbsp;</DIV>
			</td>
			<td align="right" width="10%" nowrap="true">&nbsp;</td>

			<td colspan="2">&nbsp;</td>
		</tr>
	</table>

	<p></p>
	<div style="margin-left: 30px; margin-right: 0px">
	<table border="0" cellpadding="0" cellspacing="0" width="95%">
		<tr>
			<td width="10%"><s:submit value="保存" cssClass="BtnAction"
				method="saveMerchandise"></s:submit></td>
			<td width="10%"><input type="button" class="BtnAction"
				value="返回" onClick="history.go(-1);"></td>
			<td width="80%">&nbsp;</td>
		</tr>
	</table>
	</div>
</s:form>
</body>
</html>